# coding = utf-8

'''
分析pytorch interpolatte方法
'''
import os
import numpy as np
import torch
import torch.nn.functional as F
import matplotlib.pyplot as plt


def analysis():
    path = "/datasets/DongbeiDaxue/chengkunv2/case_00035/segmentation"
    for item in sorted(os.listdir(path)):

        file_name = os.path.join(path, item)
        data = np.load(file_name)
        if np.max(data) < 2:
            continue

        print(item)
        data = torch.from_numpy(data)
        data_v1 = torch.unsqueeze(data.float(), dim=0)
        data_v1 = data_v1.unsqueeze(0)
        data_v1 = F.interpolate(data_v1, size=(256, 256), mode='bilinear')
        data_v1 = data_v1.squeeze().long()

        data_v2 = torch.unsqueeze(data.float(), dim=0)
        data_v2 = data_v2.unsqueeze(0)
        data_v2 = F.interpolate(data_v2, size=(128, 128), mode='bilinear')
        data_v2 = data_v2.squeeze().long()

        data_v3 = torch.unsqueeze(data.float(), dim=0)
        data_v3 = data_v3.unsqueeze(0)
        data_v3 = F.interpolate(data_v3, size=(64, 64), mode='bilinear')
        data_v3 = data_v3.squeeze().long()

        data_v4 = torch.unsqueeze(data.float(), dim=0)
        data_v4 = data_v4.unsqueeze(0)
        data_v4 = F.interpolate(data_v4, size=(32, 32), mode='bilinear')
        data_v4 = data_v4.squeeze().long()



        plt.subplot(1, 5, 1)
        plt.imshow(data.numpy(), cmap="gray")
        plt.subplot(1, 5, 2)
        plt.imshow(data_v1.numpy(), cmap="gray")
        plt.subplot(1, 5, 3)
        plt.imshow(data_v2.numpy(), cmap="gray")
        plt.subplot(1, 5, 4)
        plt.imshow(data_v3.numpy(), cmap="gray")
        plt.subplot(1, 5, 5)
        plt.imshow(data_v4.numpy(), cmap="gray")
        plt.show()



if __name__ == '__main__':
    analysis()